<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-xs-12">
		<div class="btn-group m-b-1" role="group">
			<?php echo admin_tab_active($menu['pay']['tab'], 'channel');?>
		</div>
	</div>
</div>

<form method="get" class="form-inline m-b-xs" action="<?php echo url('pay-channel');?>">
	<div class="row">
		<?php if(!empty($usersarr)){?>
		<div class="col-lg-2">
			<div class="form-group" style="width:100%;">

				<select name="type" class="form-control" style="width:100%;">
					<option value="0">请选择商户账号</option>
					<?php foreach($usersarr as $v){?>
					<option value="<?php echo $v['uid']?>"><?php echo $v['username'];?></option>
					<?php }?>
				</select>

			</div>
		</div>		
		<!--<div class="col-lg-3">-->
			<!--<div class="form-group" style="width:100%;">-->
				<!--<input type="text" class="form-control" name="keywords" placeholder="关键字" value="<?php echo $keywords;?>" size="15" style="width:100%;">-->
			<!--</div>-->
		<!--</div>-->
		<div class="col-lg-2">
			<button type="submit" class="btn btn-success" style="width:100%;">
				<i class="icon icon-search"></i>
				立即查询
			</button>
		</div>
		<?php }?>
		<div class="form-group">
			<a class="btn btn-primary active" href="pay-gatewayadd.htm">添加通道</a>
		</div>
	</div>
</form>

<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="table-responsive">
				<form action="<?php echo url('pay-channel');?>" method="POST">
					<table class="table table-bordered">
						<thead>
							<tr>

								<td class="text-center">名称</td>
								<td class="text-center">所属账号</td>
								<!--<td class="text-center">网关名字</td>-->
								<!--<td class="text-center">支付宝账号</td>-->
								<td class="text-center">姓名</td>
								<td class="text-center">分类</td>
								<td class="text-center">单笔最大限额</td>
								<td class="text-center">每天最大金额</td>
								<!--<td class="text-center">累计收款金额</td>-->
								<td class="text-center">状态</td>
								<td class="text-center">操作</td>
							</tr>
						</thead>
						<tbody>'

						<?php
						if(!empty($channel)){
						foreach($channel as $v){?>
							<tr style="<?php if($v['is_open']<1)echo 'background:#FFD0D0'?>">

								<td class="text-center"><?php echo $v['shortname']?></td>
								<td class="text-center"><?php echo $v['username']?></td>
								<!--<td class="text-center"><?php echo $v['gname']?></td>-->
								<!--<td class="text-center"><?php echo $v['alipay_account']?></td>-->
								<td class="text-center"><?php echo $v['alipay_realname']?></td>
								<td class="text-center"><?php echo $v['catename']?></td>
								<td class="text-center"><?php echo $v['max_limit']?></td>
								<td class="text-center"><?php echo $v['max_price']?></td>
								<!--<td class="text-center"><?php echo $v['money_total']?></td>-->
								<td class="text-center">
									<select data-id="<?php echo $v['id'];?>" class="form-control text-center open_this" name="is_open[<?php echo $v['id'];?>]">
									<option class="text-center" value="1" <?php if($v['is_open']==1){echo 'selected';} ?>>开</option>
									<option class="text-center" value="0" <?php if($v['is_open']==0){echo 'selected';} ?>>关</option>
								</select>
									<?php
									if($v['is_open']==0){
										switch ($v['close_reason']) {
											case 0:
												echo '手动关闭';
												break;
											case 1:
												echo '转账失败';
												break;
											case 2:
												echo '订单失败超限';
												break;
										}
									}
									?></td>
								<td>
									<a class="btn btn-danger del_chan" data-id="<?php echo $v['id'];?>" style="color: white">删除</a>
									<a href="<?php echo url("pay-gatewayup-$v[id]");?>" style="color: white;margin-left: 5px" class="btn btn-primary">修改</a>
									<a class="btn btn-info see_all" style="color: white;margin-left: 5px" data-id="<?php echo $v['id'];?>">查看详情</a>
								</td>
							</tr>

						<?php }
						}
						?>
						</tbody>
					</table>
					<?php
					 if(!empty($channel)){
					 foreach($channel as $v){?>
					<div class="modal fade show_<?php echo $v['id']?>" tabindex="-1" role="dialog">
						<div class="modal-dialog" role="document">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" class="guan">&times;</span></button>
									<h4 class="modal-title">通道详情</h4>
								</div>
								<div class="modal-body">
									<p>通道配置</p>
									<div class="show_li">
										<div class="show_li_li1">通道简称</div>
										<div class="show_li_li"><?php echo $v['shortname']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">通道名称</div>
										<div class="show_li_li"><?php echo $v['gname']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">支付宝appid</div>
										<div class="show_li_li"><?php echo $v['api_id']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">支付宝商户密钥</div>
										<div class="show_li_li"><input class="form-control" value="<?php echo $v['api_secret']?>"></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">支付宝公钥</div>
										<div class="show_li_li"><input class="form-control" value="<?php echo $v['api_publickey']?>"></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">支付宝网关地址</div>
										<div class="show_li_li"><?php echo $v['url']?></div>
										<div class="clear_both"></div>
									</div>
									<p>附加信息</p>

									<div class="show_li">
										<div class="show_li_li1">支付宝账户</div>
										<div class="show_li_li"><?php echo $v['alipay_account']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">姓名</div>
										<div class="show_li_li"><?php echo $v['alipay_realname']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">所属用户</div>
										<div class="show_li_li"><?php echo $v['username']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">单笔最大限额</div>
										<div class="show_li_li"><?php echo $v['max_limit']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">每日最大金额</div>
										<div class="show_li_li"><?php echo $v['max_price']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">分类</div>
										<div class="show_li_li"><?php echo $v['catename']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li">
										<div class="show_li_li1">HOST</div>
										<div class="show_li_li"><?php echo $v['host']?></div>
										<div class="clear_both"></div>
									</div>
									<div class="show_li" style="border: none">
										<div class="show_li_li1">状态</div>
										<div class="show_li_li"><?php echo $v['is_open']?'开':"关";?></div>
										<div class="clear_both"></div>
									</div>
								</div>
								<div class="modal-footer">
									<button type="button" class="btn btn-default guan" data-dismiss="modal">关闭</button>
								</div>
							</div><!-- /.modal-content -->
						</div><!-- /.modal-dialog -->
					</div>
					<?php }
						}
					?>

				</form>
			</div>
			<hr class="m-t-0" />
		</div>
		<nav class="text-center"><ul class="pagination"><?php echo $pagination; ?></ul></nav>
	</div>
</div>
<div class="zhe" style="position: fixed;z-index: 13;background: black;top: 0;left:0;display: none;width: 120%;height: 100%;opacity: 0.3"></div>
<div class="modal fade" id="delcfmModel">
	<div class="modal-dialog">
		<div class="modal-content message_align">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
				<h4 class="modal-title">提示信息</h4>
			</div>
			<div class="modal-body">
				<p>您确认要删除吗？</p>
			</div>
			<div class="modal-footer">
				<input type="hidden" id="url"/>
				<button type="button" class="btn btn-default" data-dismiss="modal" style="color: white">取消</button>
				<a  onclick="urlSubmit()" class="btn btn-success" data-dismiss="modal" style="color: white">确定</a>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>
<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<link rel="stylesheet" href="view/css/bootstrap-select.css">
<script src="view/js/bootstrap-select.js"></script>

<script>
	var delid;
	$('.del_chan').click(function () {
        delid = $(this).attr('data-id');
	    delcfm()
    });
    function delcfm(url) {
        $('#delcfmModel').modal();
    }
    function urlSubmit(){
        $.xpost("<?php echo url('pay-delchannerl');?>", {id:delid}, function(code, message){
            $.alert(message);
            if(code==1) setTimeout(function(){window.location.reload()}, 700);
        });
    }
    $('.open_this').change(function () {
		var id = $(this).attr('data-id');
		var status = $(this).val();
        $.xpost("<?php echo url('pay-upstatus');?>", {id:id,status:status}, function(code, message){
            $.alert(message);
            if(code==1) setTimeout(function(){window.location.reload()}, 700);
        });
    });
	var id;
	$('.see_all').click(function () {
		 id = $(this).attr('data-id');
		console.log(id)
		$('.show_'+id).removeClass('fade');
		$('.zhe').css('display','block');
        $('.show_'+id).css('display','block');
    });
	$('.guan').click(function () {
        $('.show_'+id).addClass('fade');
        $('.zhe').css('display','none');
        $('.show_'+id).css('display','none');
    })
var jform = $('form');
$('#submit').click(function(){
	var postdata = jform.serialize();
	$.xpost(jform.attr('action'), postdata, function(code, message){
		$.alert(message);
		if(code==1) setTimeout(function(){window.location.reload()}, 700);
	});
	return false;
});

var jconfirm = $("#confirm");
var juserlist = $('#userlist');
// 删除选中的记录
jconfirm.on('click', function(){
	var jchecked = juserlist.find('input[name="delete"]').filter(function(){ return this.checked; });
	if(jchecked.length < 1) return alert("请选择要删除的通道");
	if(!window.confirm("确认删除？")) return false;
	jchecked.each(function() {
		jtr = $(this).parents('tr');
		var uid = jtr.attr('uid');
		var passcode = $('#passcode').val();
		$.xpost(xn.url('pay-channeldel'), {id:uid,passcode:passcode}, function(code, message) {
			$.alert(message);
			if(code != 0) $('.tr'+uid).remove();
		});
	});
});

$('#nav_pc li.pay, #nav_mobile li.pay').tab('show');
</script>